package cn.zzdt4j.threadpool.message.core.service;

import cn.hutool.core.util.StrUtil;
import cn.zzdt4j.common.api.ThreadPoolConfigChange;
import cn.zzdt4j.threadpool.message.core.request.WebChangeParameterNotifyRequest;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;

import static cn.zzdt4j.common.properties.EnvironmentProperties.*;
import static cn.zzdt4j.common.properties.IdentifyProperties.IDENTIFY;

/**
 * Web thread-pool config change handler.
 *
 * @author by <a href="mailto:ligang941012@gmail.com">gang.Li</a>
 * @since 2023/10/26 17:38
 */
@Slf4j
@RequiredArgsConstructor
public class WebThreadPoolConfigChangeHandler implements ThreadPoolConfigChange<WebChangeParameterNotifyRequest> {

    private final ThreadPoolSendMessageService zzdt4jSendMessageService;

    /**
     * {@inheritDoc} for web.
     *
     * @param requestParam request param
     */
    @Override
    public void sendPoolConfigChange(WebChangeParameterNotifyRequest requestParam) {
        try {
            requestParam.setActive(active.toUpperCase());
            String appName = StrUtil.isBlank(itemId) ? applicationName : itemId;
            requestParam.setAppName(appName);
            requestParam.setIdentify(IDENTIFY);
            zzdt4jSendMessageService.sendChangeMessage(requestParam);
        } catch (Throwable th) {
            log.error("Send web thread pool config change message failed.", th);
        }
    }
}
